package com.web;

import com.bean.*;
import com.service.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class ShowIndexServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            //查询文章类型列表
            ArticleTypeService service=new ArticleTypeService();
            List<Articletype> Lt =service.getAllType();
            req.getSession().setAttribute("listType",Lt);
           // req.getRequestDispatcher("/admin/articletype/list.jsp").forward(req, resp);

            //查询文章列表
            User user=new User();
            ArticleService articleService=new ArticleService();
            List<Article> La=articleService.getAllArticle();
            req.getSession().setAttribute("listarticle",La);

            //查询所有评论
            RemarkService remarkService=new RemarkService();
            List<Remark> remark=remarkService.getAllremark();
            req.getSession().setAttribute("remark",remark);

            //查询所有留言
            WordsService wordsService = new WordsService();
            List<Words> LW=wordsService.getAllwords();
            req.getSession().setAttribute("ListWord",LW);

            //根据浏览量的获取文章列表
            List<Article> maxList=articleService.getMaxCount();
            req.getSession().setAttribute("maxList",maxList);
            //System.out.println(maxList);

            User blogger=new User();
            UserService userService=new UserService();
            blogger= userService.queryBlogger();

//            blogger= (User) req.getSession().getAttribute("user");
            req.getSession().setAttribute("blogger",blogger);
           // System.out.println("博主信息："+blogger);



            //System.out.println(user);
            if(null==user.getUsername()){
                req.getRequestDispatcher("/front/FrontIndex.jsp").forward(req, resp);
                //System.out.println("/front/FrontIndex.jsp");
            }else{
                req.getRequestDispatcher("/admin/article/ArticleList.jsp").forward(req, resp);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

}
